<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input
        v-model="listQuery.name"
        clearable
        class="filter-item"
        style="width: 200px"
        placeholder="请输入姓名"
      />
      <el-input
        v-model="listQuery.mobile"
        clearable
        class="filter-item"
        style="width: 200px"
        placeholder="请输入手机号"
      />
      <el-button
        v-permission="['GET /admin/service/type/list']"
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >查找
      </el-button>

    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="正在查询中..."
      border
      fit
      highlight-current-row
    >
      <el-table-column
        width="140"
        align="center"
        label="ID"
        prop="id"
        sortable
      />

      <el-table-column align="center" label="体检编号" prop="checkNo"/>

      <el-table-column align="center" label="姓名" prop="name"/>
      <el-table-column align="center" label="性别" prop="sex"/>
      <el-table-column align="center" label="手机号" prop="mobile"/>
      <el-table-column align="center" label="提交评估" prop="is_submit">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isSubmit == 1" type="danger">是</el-tag>
          <el-tag v-else>否</el-tag>
        </template>
      </el-table-column>

      <el-table-column align="center" label="pdf评估报告" prop="is_submit">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.pdfUrl"
            type="primary"
            size="mini"
            @click="viewPdf(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>

      <el-table-column align="center" label="创建时间" prop="createTime"/>

      <el-table-column
        align="center"
        label="操作"
        width="140"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-permission="['GET /admin/service/type/update']"
            type="primary"
            size="mini"
            @click="handleUpdate(scope.row)"
          >详情
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<style>
</style>

<script>
  import { papersList, papersDetail } from '@/api/questionnaire'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import { pdfView } from '../../utils/pdfUtils'

  export default {
    name: 'Questionnaire',
    components: { Pagination },
    data() {
      return {
        list: [],
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          name: undefined,
          mobile: undefined,
          sort: '',
          order: '',
          limit: 20
        }

      }
    },
    computed: {},
    created() {
      this.getList()
    },
    methods: {
      getList() {
        this.listLoading = true
        papersList(this.listQuery)
          .then((response) => {
            this.list = response.data.data.list
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch(() => {
            this.list = []
            this.total = 0
            this.listLoading = false
          })
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getList()
      },
      resetForm() {
        this.dataForm = {
          id: 0,
          checkIndexName: undefined,
          name: undefined,
          enable: true
        }
      },

      handleUpdate(row) {
        // 携带query参数
        console.log(row)
        this.$router.push({
          path: '/topic/detail',
          query: {
            userId: row.id
          }
        })

      },
      viewPdf(row) {
        pdfView(row.pdfUrl)
      }
    }
  }
</script>
